# TODO: Add comment
# 
# Author: E.Korsching 10.9.2009
###############################################################################



### WORK Verbesserung


### TEST
t.differential(
#			x=JP.3.sig1log.t,		#signal data w/o rezidivs
			x=testdata.volc,
			xcols=c(1:13),			#g1 check by new test data
			ycols=c(14:26),			#g2
			gin=JP.3.sig.anno,		#genome information file
			label.col="label",		#name of gene description col
			parametric=T,			#filter by t test else by U test
			Shapiro.W.alpha=0.05,	#decision if normal distribution : >alpha: H0: normal distribution -> set flag, !:outlier sensitive
			F.p.alpha=0.1,
			t.p.alpha=0.05,			#filter: t test alpha error, <=alpha: Ha: difference in means
			U.p.alpha=0.05,			#alternative for t test: non parametric: U test alpha error, <=alpha: Ha: difference in means
			F.filter=F,				#filter also according to var: keep only: >alpha: H0: no difference in var
			fold.change.k=1.5,		#filter: ratio		here:log2!
			diff.k=0.1,				#filter: difference of group means
			txt.output="output.txt",		#file name relative according to getwd() for text output
			sig.out=T,				#save results in data frame
			file.name="test.nadj",		#output name for data frame(s)
			relative.path="/results/",	#path relative according to getwd() for png type graph sheets + text file
			get.all=F,				#get all calculated values - debug algorithm
			sort="no",				#sort output by "t.p.value", "difference"
			test.corr="noadjust",			#multiple testing correction "noadjust" "Bonferroni", "Holm", "Hochberg", "SidakSS", "SidakSD", "BH", "BY"
			plot.it=T,				#plot graphs?
			volcano=T,				#plot volcano graph?
			MARGIN=2,				#margins of plot
			rows.on.page=20,		#adjust number of result rows per plot page
			cex=0.6,				#text size
			lwd=3,					#line width
			font=10,				#font number
			color.set="blueWhiteRed"		#change the 16 color palette by color.set blueWhiteRed default
)


warnings()
traceback()

#test data
#		rbinom(n=10, size=1, prob=0.5) 	#0,0.5,1: sym ansonsten asym
#		rnorm(n=10, mean=0.5, sd=1)
#		runif(n=10, min=0, max=1)

#test data binary
aa <- matrix(c(rep(20,26),
				rep(1,26),
				runif(n=26, min=0, max=1)
				)
				,26,3,byrow=F)
testdata.volc <- data.frame(
		cbind( apply(aa, 1, function(x){rbinom(n=x[1], size=x[2], prob=x[3])} )),
		row.names=paste(rep("r",20), letters[seq( from = 1, to = 20 )], seq( from = 1, to = 20 ), sep="")
		)
names(testdata.volc) <- paste(rep("c",20), letters[seq( from = 1, to = 26 )], seq( from = 1, to = 26 ), sep="")

#test data float (gene array data, assumptions: see aa)
ag1 <- matrix(c(rep(20,13),						#size / number of experiments
				rnorm(n=26, mean=200, sd=20),	#mean of experiment
				runif(n=26, min=1, max=20)		#spread of experiment
		)
		,13,3,byrow=F)
ag2 <- matrix(c(rep(20,13),						#size / number of experiments
				rnorm(n=26, mean=250, sd=20),	#mean of experiment
				runif(n=26, min=1, max=20)		#spread of experiment
		)
		,13,3,byrow=F)
aa <- rbind(ag1,ag2)
aa <- abs(aa)	#1. correct for negative values: abs
testdata.volc <- data.frame(
		cbind( apply(aa,1,function(x){rnorm(n=x[1], mean=x[2], sd=x[3])} )),
		row.names=paste(rep("r",20), letters[seq( from = 1, to = 20 )], seq( from = 1, to = 20 ), sep="")
)
names(testdata.volc) <- paste(rep("c",20), letters[seq( from = 1, to = 26 )], seq( from = 1, to = 26 ), sep="")
testdata.volc <- abs(testdata.volc)	#2. correct for negative values: abs

